cmake_minimum_required (VERSION 3.1)

# cmake -DCMAKE_TOOLCHAIN_FILE=../fuxi_setup.cmake -DDEBUG=ON ..

project(devinfo C)

# macro define...
set(JSON_LEN 2048)

# debug message
option(DEBUG "debug flag..." OFF)
if(DEBUG)
add_definitions(-DDEBUG -DDEBUG_TIME)
endif(DEBUG)

# debug message
option(SIM_SN "SIM_SN flag..." OFF)
if(SIM_SN)
add_definitions(-DSIM_SN)
endif(SIM_SN)

#message("!!! DEBUG flag:  ${DEBUG}  ${PLATFORM_NAME} ") 
message("CMAKE_TOOLCHAIN_FILE :  ${CMAKE_TOOLCHAIN_FILE} ") 

# --- 源文件列表 ---
file(GLOB SOURCES
    "${PROJECT_SOURCE_DIR}/src/*.c"
)

# 从列表中移除 测试用程序 文件
set(EXCLUDE_FILE "${PROJECT_SOURCE_DIR}/src/dtree.c")
list(REMOVE_ITEM SOURCES ${EXCLUDE_FILE})

# --- 包含目录 ---
include_directories(
    "${PROJECT_SOURCE_DIR}/src"
	"${PROJECT_SOURCE_DIR}/include"
    "${PROJECT_SOURCE_DIR}/src"
    "${PROJECT_SOURCE_DIR}/lib"
)

get_filename_component(COMPILER_NAME ${CMAKE_C_COMPILER} NAME)
message("Compiler name:  ${CMAKE_C_COMPILER}") 

# ---  构建主程序 ---
add_executable(${PROJECT_NAME} ${SOURCES})

# ---  测试用程序 device tree print 
add_executable(dtree  ${PROJECT_SOURCE_DIR}/src/dtree.c)

# --- 根据编译器，设置变量
IF (${PLATFORM_NAME} STREQUAL "peesp2") 
    # no
ELSEIF (${PLATFORM_NAME} STREQUAL "qemu_oeesp2") 
    # no
ELSEIF(${PLATFORM_NAME} STREQUAL "local")  
    # no
ELSEIF(${PLATFORM_NAME} STREQUAL "euler_sp1") 
    SET(LIB_PATH_ID  EULER)
ELSEIF(${PLATFORM_NAME} STREQUAL "fuxi")   
    SET(LIB_PATH_ID  FUXI)
ELSEIF(${PLATFORM_NAME} STREQUAL "mtk")    
    SET(LIB_PATH_ID  MTD)
ELSE()  
    message("Warning : PLATFORM_NAME ${PLATFORM_NAME} unknown.") 
ENDIF()

# ---  mqtt库路径
#target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/lib/${LIB_PATH_ID}/mqtt/libpaho-mqtt3c.a)

# ---  输出目标路径
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/target/${PLATFORM_NAME})
message("Set target to ${EXECUTABLE_OUTPUT_PATH}")

set(CMAKE_VERBOSE_MAKEFILE ON)




